package org.springblade.controller;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.cache.DeviceManagerCache;
import org.springblade.dto.EquipmentDTO;
import org.springblade.dto.ProtocolAnalysisDTO;
import org.springblade.entity.Equipment;
import org.springblade.service.IEquipmentService;
import org.springblade.vo.EquipmentVO;
import org.springblade.vo.ProtocolAnalysisVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 * @author Blade
 * @since 2023-04-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/north")
@Api(value = "", tags = "接口")
public class NorthController  {
	@Resource
	private IEquipmentService equipmentService;

	/**
	 * 查询设备列表
	 * @param  equipmentDTO 传空字符串查所有设备列表；传设备类型查该类型所有设备列表
	 * @return
	 */
	@PostMapping ("/getDeviceList")
	public List<Equipment> getDeviceList(EquipmentDTO equipmentDTO){
		return equipmentService.getDeviceList(equipmentDTO.getParentType());
	}

	/**
	 *
	 * @param equipmentDTO 传设备ID查具体设备详细状态
	 * @return
	 */
	@PostMapping("/getDeviceDetail")
	public EquipmentVO getDeviceDetail(EquipmentDTO equipmentDTO){
		return equipmentService.getDeviceDetail(equipmentDTO.getEquipmentId());
	}

	/**
	 * 根据产品id/功能id 查询控制功能列表
	 * @param protocolAnalysisDTO
	 * @return
	 */
	@PostMapping("/getControlList")
	public List<ProtocolAnalysisVO> getControlList(ProtocolAnalysisDTO protocolAnalysisDTO){
		return DeviceManagerCache.getDeviceManagerClient().getControlList(protocolAnalysisDTO);
	}

	/**
	 * 发送控制命令，推送中心业务微服务处理
	 * @param protocolAnalysisDTO
	 */
	@PostMapping("/sentControlCmd")
	public void sentControlCmd(ProtocolAnalysisDTO protocolAnalysisDTO){
		DeviceManagerCache.getDeviceManagerClient().sentControlCmd(protocolAnalysisDTO);
	}






}
